package com.lin.zoo.view;

import com.lin.zoo.controller.UserController;
import com.lin.zoo.po.Messege;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class SignPage {

    private UserController userController;

    private JLabel card =new JLabel("身份证号");
    private JLabel number = new JLabel("手机号");
    private JTextField jtaText;
    private JTextField jtbText;
    private JButton btn =new JButton("创建");
    //设置基本的页面对象


    public UserController getUserController() {
        return userController;
    }

    public void setUserController(UserController userController) {
        this.userController = userController;
    }

    public JLabel getCard() {
        return card;
    }

    public void setCard(JLabel card) {
        this.card = card;
    }

    public JLabel getNumber() {
        return number;
    }

    public void setNumber(JLabel number) {
        this.number = number;
    }

    public JTextField getJtaText() {
        return jtaText;
    }

    public void setJtaText(JTextField jtaText) {
        this.jtaText = jtaText;
    }

    public JTextField getJtbText() {
        return jtbText;
    }

    public void setJtbText(JTextField jtbText) {
        this.jtbText = jtbText;
    }

    public JButton getBtn() {
        return btn;
    }

    public void setBtn(JButton btn) {
        this.btn = btn;
    }
    public void createAndShowGUI(){

        JFrame frame =new JFrame("创建个人信息");
        frame.setVisible(true);
        frame.setSize(600,450);

        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        // 显示窗口
        frame.setResizable(false);
        //固定窗口大小不被修改
        frame.setLocationRelativeTo(null);
        //窗口处于中央

        init();
        frame.setLayout(null);
        frame.add(card);
        frame.add(number);
        frame.add(jtaText);
        frame.add(jtbText);
        frame.add(btn);

        getBtn().addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String card = getJtaText().getText();
                String number = getJtbText().getText();
                //获取信息
                setUserController(new UserController());
                Messege messege =getUserController().signvisitor(card,number);
                if(messege.getResult().equals("创建成功")){
                    frame.setVisible(false);
                    System.out.println(messege);
                    JOptionPane.showMessageDialog(null, messege.getResult(), null, JOptionPane.PLAIN_MESSAGE);
                    new StartPage("主页面").setVisible(true);
                }
                else {
                    System.out.println(messege);
                    JOptionPane.showMessageDialog(null, messege.getResult(), null, JOptionPane.PLAIN_MESSAGE);
                }
            }
        });


    }
    public void init(){

        card.setSize(60,20);
        card.setLocation(160,80);

        number.setSize(50,20);
        number.setLocation(180,120);

        jtaText = new JTextField();
        jtaText.setSize(190,30);
        jtaText.setLocation(230,80);

        jtbText = new JTextField();
        jtbText.setSize(190,30);
        jtbText.setLocation(230,120);

        btn.setSize(90,30);
        btn.setLocation(260,180);
    }
}
